package projectATMFinal;

import javax.swing.JApplet;
import javax.swing.JPanel;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Color;

public class ATM extends JApplet {
	private JTextField txtWelcomeToThe, txtInput;
	private static JTextField txtDirections;
	private String pinEntered = "Please Enter Your PIN";
	private String userInput = "";
	private String directions1 = "Enter lol Amount";
	private String directions2 = "1 = $20, 2 = $50, 3 = $100";
	private JButton btnDeposit, btnWithdraw;
	static ATMFunctions functions = new ATMFunctions();

	public void init() {
		setSize(500, 316);
	}

	public ATM() {
		getContentPane().setForeground(Color.GREEN);
		getContentPane().setBackground(Color.PINK);
		setForeground(Color.GREEN);
		setBackground(Color.PINK);
		getContentPane().setLayout(null);

		JPanel panel = new JPanel();
		panel.setForeground(Color.GREEN);
		panel.setBackground(Color.DARK_GRAY);
		panel.setBounds(258, 11, 229, 292);
		getContentPane().add(panel);
		panel.setLayout(new GridLayout(5, 3, 0, 0));

		JButton button = new JButton("1");
		button.setBackground(Color.BLACK);
		button.setForeground(Color.PINK);
		button.setFont(new Font("Tahoma", Font.BOLD, 16));
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if (btnWithdraw.isSelected()) {
					functions.withdrawFunds("20");
				} else {
					userInput = userInput + 1;
					txtInput.setText(userInput);
				}
			}
		});
		panel.add(button);

		JButton button_1 = new JButton("2");
		button_1.setForeground(Color.PINK);
		button_1.setBackground(Color.BLACK);
		button_1.setFont(new Font("Tahoma", Font.BOLD, 16));
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if (btnWithdraw.isSelected()) {
					functions.withdrawFunds("50");
				} else {
					userInput = userInput + 1;
					txtInput.setText(userInput);
				}
			}
		});
		panel.add(button_1);

		JButton button_2 = new JButton("3");
		button_2.setForeground(Color.PINK);
		button_2.setBackground(Color.BLACK);
		button_2.setFont(new Font("Tahoma", Font.BOLD, 16));
		button_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if (btnWithdraw.isSelected()) {
					functions.withdrawFunds("100");
				} else {
					userInput = userInput + 1;
					txtInput.setText(userInput);
				}
			}
		});
		panel.add(button_2);

		JButton button_3 = new JButton("4");
		button_3.setForeground(Color.PINK);
		button_3.setBackground(Color.BLACK);
		button_3.setFont(new Font("Tahoma", Font.BOLD, 16));
		button_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				userInput = userInput + 4;
				txtInput.setText(userInput);
			}
		});
		panel.add(button_3);

		JButton button_4 = new JButton("5");
		button_4.setForeground(Color.PINK);
		button_4.setBackground(Color.BLACK);
		button_4.setFont(new Font("Tahoma", Font.BOLD, 16));
		button_4.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				userInput = userInput + 5;
				txtInput.setText(userInput);
			}
		});
		panel.add(button_4);

		JButton button_5 = new JButton("6");
		button_5.setForeground(Color.PINK);
		button_5.setBackground(Color.BLACK);
		button_5.setFont(new Font("Tahoma", Font.BOLD, 16));
		button_5.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				userInput = userInput + 6;
				txtInput.setText(userInput);
			}
		});
		panel.add(button_5);

		JButton button_6 = new JButton("7");
		button_6.setForeground(Color.PINK);
		button_6.setBackground(Color.BLACK);
		button_6.setFont(new Font("Tahoma", Font.BOLD, 16));
		button_6.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				userInput = userInput + 7;
				txtInput.setText(userInput);
			}
		});
		panel.add(button_6);

		JButton button_7 = new JButton("8");
		button_7.setForeground(Color.PINK);
		button_7.setBackground(Color.BLACK);
		button_7.setFont(new Font("Tahoma", Font.BOLD, 16));
		button_7.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				userInput = userInput + 8;
				txtInput.setText(userInput);
			}
		});
		panel.add(button_7);

		JButton button_8 = new JButton("9");
		button_8.setForeground(Color.PINK);
		button_8.setBackground(Color.BLACK);
		button_8.setFont(new Font("Tahoma", Font.BOLD, 16));
		button_8.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				userInput = userInput + 9;
				txtInput.setText(userInput);
			}
		});
		panel.add(button_8);

		JButton button_9 = new JButton(".");
		button_9.setForeground(Color.PINK);
		button_9.setBackground(Color.BLACK);
		button_9.setFont(new Font("Tahoma", Font.BOLD, 16));
		button_9.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				userInput = userInput + ".";
				txtInput.setText(userInput);
			}
		});
		panel.add(button_9);

		JButton button_10 = new JButton("0");
		button_10.setForeground(Color.PINK);
		button_10.setBackground(Color.BLACK);
		button_10.setFont(new Font("Tahoma", Font.BOLD, 16));
		button_10.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				userInput = userInput + 0;
				txtInput.setText(userInput);
			}
		});
		panel.add(button_10);

		JButton btnEnter = new JButton("Enter");
		btnEnter.setForeground(Color.PINK);
		btnEnter.setBackground(Color.BLACK);
		btnEnter.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if (pinEntered == "Please Enter Your PIN") {
					pinEntered = "Thank You!";
					txtDirections.setText(pinEntered + " lol");
					userInput = "";
					txtInput.setText(userInput);
				}
				if (pinEntered == "Thank You!") {
					if (btnDeposit.isSelected()) {
						functions.addFunds(userInput);
						userInput = "";
						btnDeposit.setSelected(false);
						txtInput.setText("");
					}
					if (btnWithdraw.isSelected()) {
						functions.withdrawFunds(userInput);
						userInput = "";
						btnWithdraw.setSelected(false);
						txtInput.setText("");
					}
				}
			}
		});
		panel.add(btnEnter);

		JButton btnBalanceCheck = new JButton("Balance");
		btnBalanceCheck.setForeground(Color.PINK);
		btnBalanceCheck.setBackground(Color.BLACK);
		btnBalanceCheck.setFont(new Font("Tahoma", Font.PLAIN, 9));
		btnBalanceCheck.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if (pinEntered == "Thank You!") {
					functions.printBalance();
				}
			}
		});
		panel.add(btnBalanceCheck);

		btnDeposit = new JButton("Deposit");
		btnDeposit.setForeground(Color.PINK);
		btnDeposit.setBackground(Color.BLACK);
		btnDeposit.setFont(new Font("Tahoma", Font.PLAIN, 9));
		btnDeposit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				userInput = "";
				if (pinEntered == "Thank You!") {
					txtInput.setText("");
					btnDeposit.setSelected(true);
					btnWithdraw.setSelected(false);
					txtDirections.setText(directions1);
				}
			}
		});
		panel.add(btnDeposit);

		btnWithdraw = new JButton("Withdraw");
		btnWithdraw.setForeground(Color.PINK);
		btnWithdraw.setBackground(Color.BLACK);
		btnWithdraw.setFont(new Font("Tahoma", Font.PLAIN, 9));
		btnWithdraw.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				userInput = "";
				if (pinEntered == "Thank You!") {
					txtInput.setText("");
					btnWithdraw.setSelected(true);
					btnDeposit.setSelected(false);
					txtDirections.setText(directions2);
				}
			}
		});
		panel.add(btnWithdraw);

		JPanel panel_1 = new JPanel();
		panel_1.setBackground(Color.BLACK);
		panel_1.setBounds(10, 11, 238, 99);
		getContentPane().add(panel_1);
		panel_1.setLayout(null);

		txtWelcomeToThe = new JTextField();
		txtWelcomeToThe.setForeground(Color.PINK);
		txtWelcomeToThe.setBackground(Color.BLACK);
		txtWelcomeToThe.setEditable(false);
		txtWelcomeToThe.setFont(new Font("Tahoma", Font.BOLD, 18));
		txtWelcomeToThe.setHorizontalAlignment(SwingConstants.CENTER);
		txtWelcomeToThe.setBounds(10, 11, 218, 77);
		txtWelcomeToThe.setText("LOL ATM LOL");
		panel_1.add(txtWelcomeToThe);
		txtWelcomeToThe.setColumns(10);

		txtDirections = new JTextField();
		txtDirections.setFont(new Font("Tahoma", Font.BOLD, 14));
		txtDirections.setBackground(Color.BLACK);
		txtDirections.setForeground(Color.PINK);
		txtDirections.setHorizontalAlignment(SwingConstants.CENTER);
		txtDirections.setEditable(false);
		txtDirections.setText("Please Enter Your lol PIN");
		txtDirections.setBounds(10, 121, 238, 88);
		getContentPane().add(txtDirections);
		txtDirections.setColumns(10);

		txtInput = new JTextField();
		txtInput.setBackground(Color.BLACK);
		txtInput.setForeground(Color.GREEN);
		txtInput.setFont(new Font("Tahoma", Font.PLAIN, 16));
		txtInput.setHorizontalAlignment(SwingConstants.CENTER);
		txtInput.setEditable(false);
		txtInput.setText(userInput);
		txtInput.setBounds(10, 220, 238, 83);
		getContentPane().add(txtInput);
		txtInput.setColumns(10);

	}

	public static void updateDisplay(String string) {
		txtDirections.setText(string + " lol");
	}
}
